<%@ page language="java" import="weaver.conn.RecordSet" pageEncoding="UTF-8" %>
<%@ page import="weaver.general.BaseBean" %>
<%@ page import="weaver.general.Util" %>
<%--流程退回调用QMS接口--%>
<%
    BaseBean baseBean = new BaseBean();
    String subcompanyids = "522,521";//中环领先
    RecordSet rs = new RecordSet();
    rs.executeQuery("select id,workflowname,abs(formid) formid,subcompanyid from workflow_base where subcompanyid not in (" + subcompanyids + ")");
    int counts = rs.getCounts();
    int succcount = 0;
    int failcount = 0;
    while (rs.next()) {
        String workflowid = Util.null2String(rs.getString("id"));
        String workflowname = Util.null2String(rs.getString("workflowname"));
        String formid = Util.null2String(rs.getString("formid"));
        String subcompanyid = Util.null2String(rs.getString("subcompanyid"));
        boolean status = deleteWfData(workflowid, formid, workflowname);
        if (status) {
            succcount++;
        } else {
            failcount++;
        }
        out.print(">>>>>ClearWfData>>>>>subcompanyid=" + subcompanyid + ",workflowid=" + workflowid + ",workflowname=" + workflowname
                + ",formid=" + formid + ",是否删除成功状态：" + status + "<br/>");
        baseBean.writeLog(">>>>>ClearWfData>>>>>subcompanyid=" + subcompanyid + ",workflowid=" + workflowid + ",workflowname=" + workflowname
                + ",formid=" + formid + ",是否删除成功状态：" + status);
    }
    out.print(">>>>>ClearWfData>>>>总记录数：" + counts + ",成功记录数：" + succcount + ",失败记录数：" + failcount + "<br/>");
    baseBean.writeLog(">>>>>ClearWfData>>>>总记录数：" + counts + ",成功记录数：" + succcount + ",失败记录数：" + failcount);
%>

<%!

    /**
     *@Description: 删除流程数据
     *@Param: [nodeid]
     *@return: java.lang.String
     *@Author: Dusongsong
     *@Date: 2023/03/21
     */
    public static boolean deleteWfData(String workflowid, String formid, String workflowname) {
        BaseBean baseBean = new BaseBean();
        baseBean.writeLog(">>>>>deleteWfData>>>>workflowid=" + workflowid + ",formid=" + formid + ",workflowname=" + workflowname);
        RecordSet rs = new RecordSet();
        boolean flag = false;
        boolean requestbaseFlag = rs.executeUpdate("delete from workflow_requestbase where workflowid=?", workflowid);
        boolean requestlogFlag = rs.executeUpdate("delete from workflow_requestlog where workflowid=?", workflowid);
        boolean currentoperatorFlag = rs.executeUpdate("delete from workflow_currentoperator where workflowid=?", workflowid);
        boolean requestdeletelogFlag = rs.executeUpdate("delete from workflow_requestdeletelog where workflow_id=?", workflowid);
        baseBean.writeLog(">>>>>deleteWfData>>>>workflow_requestbase=" + requestbaseFlag);
        baseBean.writeLog(">>>>>deleteWfData>>>>workflow_requestlog=" + requestlogFlag);
        baseBean.writeLog(">>>>>deleteWfData>>>>workflow_currentoperator=" + currentoperatorFlag);
        baseBean.writeLog(">>>>>deleteWfData>>>>workflow_requestdeletelog=" + requestdeletelogFlag);
        boolean requestoperatelogFlag = deleteOperatLog(formid);
        baseBean.writeLog(">>>>>deleteWfData>>>>workflow_requestoperatelog=" + requestoperatelogFlag);
        if (requestoperatelogFlag) {
            flag = deleteDetail(formid);
        }
        return flag;
    }

    /**
     *@Description: 删除节点操作明细记录日志
     *@Param: [nodeid]
     *@return: java.lang.String
     *@Author: Dusongsong
     *@Date: 2023/03/21
     */
    public static boolean deleteOperatLog(String formid) {
        RecordSet rs = new RecordSet();
        rs.executeQuery("select requestid from formtable_main_" + formid + " where 1=1");
        int counts = rs.getCounts();
        int count = 0;
        while (rs.next()) {
            String requestid = Util.null2String(rs.getString("requestid"));
            boolean flag = rs.executeUpdate("delete from workflow_requestoperatelog where requestid=?", requestid);
            if (flag) {
                count++;
            }
        }
        return counts == count;
    }

    /**
     *@Description: 删除明细
     *@Param: [nodeid]
     *@return: java.lang.String
     *@Author: Dusongsong
     *@Date: 2023/03/21
     */
    public static boolean deleteDetail(String formid) {
        RecordSet rs = new RecordSet();
        boolean flag = false;
        rs.executeQuery("select tablename from workflow_billdetailtable where abs(billid)=?", formid);
        int counts = rs.getCounts();
        int count = 0;
        while (rs.next()) {
            String tablename = Util.null2String(rs.getString("tablename"));
            boolean flag1 = rs.executeUpdate("delete from " + tablename + " where 1=1");
            if (flag1) {
                count++;
            }
        }
        if (counts == count) {
            flag = rs.executeUpdate("delete from formtable_main_" + formid + " where 1=1");
        }
        return flag;
    }

%>




